package abg.manage.controller.sys;

import abg.core.common.security.ReSubmit;
import abg.core.domain.sys.SRS;
import abg.core.service.common.CaptchaService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/manage/system/captcha")
public class CaptchaController {
    @Resource
    private CaptchaService captchaService;

    /**
     * 登录验证码
     */
    @PostMapping("/loginCaptchaImg")
    public SRS<Object> loginCaptchaImg() {
        return SRS.bySuccess(captchaService.getLoginImg());
    }

    /**
     * 发送邮箱注册验证码
     */
    @ReSubmit
    @PostMapping("/emailRegister")
    public SRS<Object> emailRegister(String toEmail) {
        boolean b = captchaService.sendEmailRegister(toEmail);
        return SRS.bySuccess(b);
    }

    /**
     * 发送手机注册验证码
     */
    @ReSubmit
    @PostMapping("/phoneRegister")
    public SRS<Object> phoneRegister(String toPhone) {
        boolean b = captchaService.sendPhoneRegister(toPhone);
        return SRS.bySuccess(b);
    }

}
